package com.yyx.app1.DiagnosticTools_function.UI.NineFunction_Activity;

import android.app.Activity;
import android.util.Log;
import android.view.Gravity;
import android.widget.LinearLayout;
import android.widget.TextView;

import com.yyx.app1.CommonControls.CloudComputing_Control.CloudComputing_Control;
import com.yyx.app1.CommonControls.CloudComputing_Control.CloudComputing_Control_;
import com.yyx.app1.CommonControls.CloudComputing_Control.CloudComputing_Control_Adapter;
import com.yyx.app1.CommonControls.EditTextItemControl.EditTextItemControl;
import com.yyx.app1.CommonControls.EditTextItemControl.OnEditTextItemControl_EditTextChange_Listener;
import com.yyx.app1.R;

import org.androidannotations.annotations.AfterViews;
import org.androidannotations.annotations.Background;
import org.androidannotations.annotations.Click;
import org.androidannotations.annotations.EActivity;
import org.androidannotations.annotations.UiThread;
import org.androidannotations.annotations.ViewById;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Objects;

/**
 * Created by yuexing on 2015/9/10.
 */
@EActivity(R.layout.activity_commonlyusedformulas_basefunction)
public class DiagnosticTools_CommonlyUsedFormulas_FirstFunction_Activity extends Activity{
    private String[] requres=new String[]{"人用尿比重仪器值"};
    private String[] results = new String[]{"矫正值"};
    private String title="尿比重校正值";

    @ViewById
    CloudComputing_Control layout_base;

    @AfterViews
    public void inti()
    {
        CloudComputing_Control_Adapter adapter=new CloudComputing_Control_Adapter() {
            @Override
            public void backgroundComputing(List<HashMap<String, String>> DataList) {
                getData(DataList);
            }
        };
        layout_base.OnCreate(requres, results, title, adapter);
        TextView view = new TextView(this);
        view.setText("输入范围提示1.000-1.080");
        view.setGravity(Gravity.CENTER);
        layout_base.getCloudComputingControl_require().addView(view);
    }

    @Background
    public void getData(List<HashMap<String, String>> DataList )
    {
        List<HashMap<String, Object>> data = new ArrayList<>();
        for(int i = 0 ; i<results.length ;++i)
        {
            HashMap<String,Object> map = new HashMap<>();
            map.put("key",results[i]);
            map.put("value", operation(DataList.get(i).get("value")));
            data.add(map);
        }
        setData(data);
    }

    @UiThread
    public void setData(List<HashMap<String, Object>> data)
    {
        TextView[] controls = layout_base.getResults();
        for (int i=0 ; i< controls.length ; ++i)
        {
            controls[i].setText(""+data.get(i).get("value"));
        }
    }

    public String operation(String dat)
    {
        double aDouble;
        try {
            aDouble = Double.valueOf(dat);
            aDouble = aDouble*0.846;
            aDouble = aDouble + 0.154;
            String str=null;
            if (aDouble<1.008 ||aDouble>1.03)
                str ="犬尿比重="+ aDouble+"\n"+"可以排除慢性肾衰";
            else if (aDouble>1.008 && aDouble<1.03)
                str = "犬尿比重="+ aDouble+"\n"+"慢性肾衰可疑，特别是在脱水和/或氮质血症出现时";
            String str2=null;
            if (aDouble<1.008 ||aDouble>1.045)
                str2 ="猫尿比重="+ aDouble+"\n"+"可以排除慢性肾衰";
            else if (aDouble>1.008 && aDouble<1.045)
                str2 = "猫尿比重="+ aDouble+"\n"+"慢性肾衰可疑，特别是在脱水和/或氮质血症出现时";
            return str+"\n\n"+str2;
        }
        catch (Exception e)
        {
            Log.e("异常1509301407",e.toString());
            return "";
        }
    }
}
